exports.__esModule = true;

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

exports.default = class extends think.BaseController {
  __before() {
    this.testKey = 'testkey';
  }

  /**
     * 查询全部部件分类
     */
  getAllPartGroupAction() {
    var _this = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const EventService = _this.service('api/cms/PartsService');
      const res = yield EventService.getAllPartGroup();
      if (!res.error) {
        aj.result = res;
      } else {
        aj.success = false;
        aj.msg = '数据库查询错误';
      }
      return _this.json(aj);
    })();
  }
  /**
     * 根据百度原点坐标和范围（米）获取部件列表
     */
  getPartsListByRangeAction() {
    var _this2 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const data = {
        baidu_x: Number(_this2.post('baidu_x')),
        baidu_y: Number(_this2.post('baidu_y')),
        range: Number(_this2.post('range'))
      };
      const PartsService = _this2.service('api/cms/PartsService');
      const res = yield PartsService.getPartsListByRange(data);
      if (!res.error) {
        aj.result = res;
      } else {
        aj.success = false;
        aj.msg = '获取部件列表失败';
      }
      return _this2.json(aj);
    })();
  }
  /**
     * 根据行政区域代码|部件分类|用户id获取部件列表
     */
  getPartsListByAreaAction() {
    var _this3 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const data = {};
      if (_this3.post('area_code')) {
        data.area_code = _this3.post('area_code');
      }
      if (_this3.post('group_code')) {
        data.group_code = _this3.post('group_code');
      }
      if (_this3.post('ObjState')) {
        data.ObjState = _this3.post('ObjState');
      }
      if (_this3.post('userId')) {
        data.create_by = _this3.post('userId');
      }
      if (_this3.post('startTime')) {
        data.startTime = _this3.post('startTime');
      }
      if (_this3.post('endTime')) {
        data.endTime = _this3.post('endTime');
      }
      const PartsService = _this3.service('api/cms/PartsService');
      const res = yield PartsService.getPartsListByArea(data);
      if (!res.error) {
        aj.result = res;
      } else {
        aj.success = false;
        aj.msg = '获取部件列表失败';
      }
      return _this3.json(aj);
    })();
  }

  getCountByAreaAction() {
    var _this4 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const PartsService = _this4.service('api/cms/PartsService');
      const res = yield PartsService.getCountByArea();
      if (!res.error) {
        aj.result = res;
      } else {
        aj.success = false;
        aj.msg = '查询区域部件数量信息错误';
      }
      return _this4.json(aj);
    })();
  }
  getCountByStateAction() {
    var _this5 = this;

    return _asyncToGenerator(function* () {
      const aj = think.ajaxJson();
      const PartsService = _this5.service('api/cms/PartsService');
      const res = yield PartsService.getCountByState();
      if (!res.error) {
        aj.result = res;
      } else {
        aj.success = false;
        aj.msg = '查询部件统计信息错误';
      }
      return _this5.json(aj);
    })();
  }
  __call() {}
};